package com.itheima.stock.controller;

import com.itheima.stock.pojo.StockBusiness;
import com.itheima.stock.service.StockService;
import com.itheima.stock.vo.resp.PageResult;
import com.itheima.stock.vo.resp.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author by itheima
 * @Date 2021/12/19
 * @Description
 */
@RestController
@RequestMapping("/api/quot")
public class StockController {

    @Autowired
    private StockService stockService;

    /**
     * 查询个股日K线详情
     * @param code
     * @return
     */
    @GetMapping("/stock/screen/dkline")
    public R<List<Map>> getDayKLinData(String code){
        return stockService.getDayKLinData(code);
    }

    /**
     * 查询个股 分时k线详情
     * @param stockCode
     * @return
     */
    @GetMapping("/stock/screen/time-sharing")
    public R<List<Map>> getStockRtInfoByCode4EvrMinute(@RequestParam("code") String stockCode){
        return stockService.getStockScreenMinuteSharing(stockCode);
    }

    /**
     * 如果当前不在交易日内,则以上一个有效交易日进行查询
     * 统计每分钟个股的涨跌幅
     * @return
     */
    @GetMapping("/stock/updown")
    public R<Map> getStockUpDown(){
        return stockService.getStockUpDownScope();
    }

    /**
     * 查询大盘成交量对比
     * @return
     */
    @GetMapping("/stock/tradevol")
    public R<Map> getStockTravolCompare(){
        return stockService.getStockTravolCompare();
    }


    /**
     * 涨幅榜数据分页导出到excel
     * @param response 用于响应excel文件
     * @param page 当前页
     * @param pageSize 每页大小
     */
    @GetMapping("/stock/export")
    public void exPort(HttpServletResponse response, Integer page, Integer pageSize) throws IOException {
        this.stockService.exportStockExcel(response,page,pageSize);
    }

    /**
     * 涨停跌停数
     * 沪深两市涨跌停分时行情数据查询，查询T日每分钟的涨跌停数据
     * @return
     */
    @GetMapping("/stock/updown/count")
    public R<Map> getStockUpDownCount(){
        return stockService.getStockUpDownLimitCount();
    }

    /**
     * 沪深两市个股行情列表查询 ,以时间顺序和涨幅排序分页查询
     * @param page 当前页
     * @param pageSize 每页大小
     * @return
     */
    @GetMapping("/stock/all")
    public R<PageResult> getStockAll(Integer page, Integer pageSize){
        return stockService.getStockAll(page,pageSize);
    }

    /**
     * 首页:查询个股涨幅 前10
     */
    @GetMapping("/stock/increase")
    public R<List<Map>> getStockIncrease(){
        return stockService.getStockIncrease();
    }



    /**
     * 查询最新板块数据前10
     * @return
     */
    @GetMapping("/sector/all")
    public R<List<Map>> getSectorAll(){
        return stockService.getSectorAllLimit();
    }

    /**
     * 获取国内最新大盘指数
     * @return
     */
    @GetMapping("/index/all")
    public R<List<Map>> getInnerStockMarket(){
        return stockService.getInnerStockMarket();
    }


    @GetMapping("/stock/business/all")
    public List<StockBusiness> getAllBusiness(){
        return stockService.getAllStockBusiness();
    }
}    